<template>
  <div class="user-wrapper">
    <div class="content-box">
      <a v-if="apiUrl" :href="apiUrl" target="_blank">
        <span class="action"></span>
      </a>
      <a-dropdown>
        <span class="action ant-dropdown-link1 user-dropdown-menu">
          <a-avatar class="avatar" icon="user" size="small" :src="userInfo.img"/>
          <span>{{ userInfo.name || '未登录' }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <a-menu-item key="1" @click="linkToSetting">
            <a-icon type="setting"/>
            <span>个人设置</span>
          </a-menu-item>
          <a-menu-item key="3">
            <a href="javascript:;" @click="logout">
              <a-icon type="logout"/>
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'

export default {
  data () {
    return {
      apiUrl: ''
    }
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.info,
      authUrl: state => state.user.authUrl
    })
  },
  created () {
    // this.GetInfo()
  },
  methods: {
    ...mapActions(['Logout', 'GetInfo']),
    linkToSetting () {
      const { href } = location
      window.open(this.authUrl + '/#/user-account/personalSetting?from=' + encodeURIComponent(href), '_blank')
    },
    logout () {
      this.Logout({ isReqLogOut: true }).then(res => {
        console.log('退出成功')
      })
    }
  }
}
</script>
